package com.easyfun.healthmagicbox.comm;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.easyfun.healthmagicbox.ormlite.ServerResponseCode;
import com.easyfun.healthmagicbox.pojo.ConstantData;
import com.easyfun.healthmagicbox.sync.CommCallback;


public class PictureDeleteTask extends BaseRedoTask{

	String picSyncID = "";
	
	public PictureDeleteTask(Context context, CommCallback callback) {
		super(context, callback);
	}
	public PictureDeleteTask(Context context, CommCallback callback, String syncid) {
		super(context, callback);
		picSyncID = syncid;
	}

	@Override
	public void run() {
		JSONObject serializedObj = new JSONObject();
		Map<String, String> parmas = new HashMap<String, String>();	  
		String result = "";
		try {
			serializedObj.put("picSyncID", picSyncID);		 
			parmas.put("jsonstring", serializedObj.toString());
		} catch (JSONException e1) {
			ccb.setCommResult(this, result,
					ServerResponseCode.FAILED);
			e1.printStackTrace();
			return;
		}
	    
		try {
			result = super.uploadByHTTP(parmas, ConstantData.PictureDeleteURI);
		} catch (ClientProtocolException e) {
			ccb.setCommResult(this, result,
					ServerResponseCode.FAILED);
			e.printStackTrace();
			return;
		} catch (IOException e) {
			ccb.setCommResult(this, result,
					ServerResponseCode.FAILED);
			e.printStackTrace();
			return;
		}
		if ((ServerResponseCode.parseOf(result)==ServerResponseCode.SUCCESS))
		{

			ccb.setCommResult(this, result,
					ServerResponseCode.SUCCESS);
		}else
		{
			ccb.setCommResult(this, result,
					ServerResponseCode.FAILED);
			return;
		}
		
	}

	@Override
	public String serializeParam() throws IllegalArgumentException {
		return picSyncID;
	}

	@Override
	public void deserializeParam(String serialstring)
			throws IllegalArgumentException {
		picSyncID = serialstring;		
	}
}
